﻿using MtApi;
using MTEA.LIB;
using MTEA.LIB.Analysis;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MTEA.MTTask
{
    public class BollingMTTask : MTTask<BollingMTTask.BollingMTTaskConfig>
    {
        public static readonly string Tag = "BollingMTTask";
        public class BollingMTTaskConfig : MTTaskConfig
        {
            public double Duration { get; set; }

            public int BollingType { get; set; }
        }

        public BollingMTTask(BollingMTTaskConfig config) : base(config)
        {
            Name = "Bolling Task";
            Description = MTTaskConfig.GetDescription(config);
        }
        public override void Execute(MTTaskContext context)
        {
            base.Execute(context);
            double bollingValue = -1;
            switch (config.BollingType)
            {
                case 0:
                    bollingValue = client.getBollingMain(context.Symbol, config.TimeFrames, 0);
                    break;
                case 1:
                    bollingValue = client.getBollingUpper(context.Symbol, config.TimeFrames, 0);
                    break;
                case 2:
                    bollingValue = client.getBollingLower(context.Symbol, config.TimeFrames, 0);
                    break;
                default:
                    throw new ArgumentException("Invalid BollingType");
            }

            double dur = Math.Abs(client.iClose(context.Symbol, (ChartPeriod)config.TimeFrames, 0) - bollingValue);

            if (dur < config.Duration)
            {
                isFinished= OrderTrade(Tag, context);
                return;
            }
            isFinished = false;
        }
       
    }

}
